// Variables
- latest_version = current_page.metadata[:page][:version] == $last_version
- legacy_version = current_page.metadata[:page][:version] < $last_version
- language_code = current_page.metadata[:page][:language]
- versions = Dir.entries("source/#{language_code}") - %w[. ..]
- current_version = current_page.metadata[:page][:version]
- newer_version_available = File.exists?("source/#{language_code}/#{$last_version}")

!!! 5
%html
  %head{ lang: current_page.data.language }
    %meta{ charset: 'utf-8' }
    %meta{ content: 'IE=edge', 'http-equiv' => 'X-UA-Compatible' }
    %meta{ name: 'viewport', content: 'width=device-width, initial-scale=1.0' }
    %meta{ name: 'description', content: current_page.data.description }

    -# Open Graph

    %meta{ property: 'og:article:publisher', content: config.publisher_url }
    %meta{ property: 'og:title', content: current_page.data.title }
    %meta{ property: 'og:type', content: 'article' }
    %meta{ property: 'og:url', content: path_to_url(current_page.url) }
    %meta{ property: 'og:description', content: current_page.data.description }
    %meta{ property: 'og:image', content: image_path("logo.png") }
    = yield_content :og

    -# Icons

    %link{ rel: "shortcut icon", type: "image/x-icon", href: image_path("favicon.ico") }
    %link{ rel: 'canonical', href: path_to_url(current_page.url) }

    %title= current_page.data.title

    %link{ rel: "stylesheet", href: "https://fonts.googleapis.com/css?family=Muli:400,700" }
    = stylesheet_link_tag '//fonts.googleapis.com/css?family=Source+Code+Pro:400,700'
    - if legacy_version
      = stylesheet_link_tag 'legacy'
    - else
      = stylesheet_link_tag 'application'
    = javascript_include_tag 'all', defer: true

  %body
    %article
      %header{ role: "banner" }
        - if latest_version
          = image_tag "keep-a-changelog-mark.svg", width: 100, class: "mark"
        %nav.locales{ role: "navigation" }
          %select
            - $languages.each do |language|
              - selected = language_code == language.first
              - if available_translation = available_translation_for(language)
                %option{ selected: selected, label: available_translation, value: language.first }
                  = available_translation

      .main{ role: "main" }
        - if !latest_version && legacy_version
          - if versions.include?($last_version)
            %p.newer
              - if $languages[language_code][:new]
                = "#{$languages[language_code][:new]}: "
              - else
                There is a newer version available:
              = link_to "#{$languages[language_code][:name]} #{$last_version}", "/#{language_code}/#{$last_version}"
          - else
            - if $languages[language_code][:notice]
              %p.last-version-notice= $languages[language_code][:notice]
            - else
              %p.last-version-notice
                The latest version (#{$last_version}) is not yet available in
                this language but
                = link_to "you can read it in English", "/en/#{$last_version}"
                for now and
                = link_to "help translate ", "https://github.com/olivierlacan/keep-a-changelog/issues"
                it.

        = yield

        %footer.footer.clearfix{ role: "banner" }
          = image_tag "keep-a-changelog-mark.svg", width: 30, class: "mark"

          %p.about
            This project is
            = link_to "MIT Licensed", "http://choosealicense.com/licenses/mit/"
            \ //
            = link_to "Created & maintained", "https://github.com/olivierlacan/keep-a-changelog/"
            by
            = link_to "Olivier Lacan", "http://olivierlacan.com/"
            \ //
            Designed by
            = link_to "Tyler Fortune", "http://tylerfortune.me/"

  - unless config.gauges_id.blank?
    :javascript
      var _gauges = _gauges || [];
      (function() {
        var t   = document.createElement('script');
        t.type  = 'text/javascript';
        t.async = true;
        t.id    = 'gauges-tracker';
        t.setAttribute('data-site-id', '#{config.gauges_id}');
        t.src = '//secure.gaug.es/track.js';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(t, s);
      })();
